<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>人员管理</title>
<#assign base=request.contextPath  />
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="${base}/js/layui/css/layui.css"  media="all">
    <script type="text/javascript" src="${base}/js/zhang.js"></script>
<style type="text/css">
  form{
      		padding: 20px;
      	}
      	.layui-btn-radius{
        			border-radius: 5px;
        		}
  </style>
</head>
<body>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  <legend>人员管理</legend>
</fieldset> 
	                    <div class="demoTable"style="padding:15px;">
<button class="layui-btn layui-btn-radius" id="btn2" data-method="offset" type="button" style="background-color: #0092EF;">添加人员</button>
    					<div style="float:right">
    						  <div class="layui-inline ">
    						    <input class="layui-input" name="id" id="demoReload" autocomplete="off">
    						  </div>
    						  <button class="layui-btn layui-btn-radius" id="btn1" onclick="selectUser()" data-type="reload" style="background-color: #0092EF;">搜索</button>
    						  </div>
    						  </div>
		<table class="layui-hide" lay-filter="user" id="test"></table>
<script type="text/html" id="barDemo">
  <#--<i class="layui-icon layui-icon-edit" lay-event="edit" style="font-size: 20px;"></i>&nbsp;&nbsp;&nbsp;-->
  <i class="layui-icon layui-icon-delete layui-btn-xs" lay-event="del"  href="javascript:void(0)"  onclick="delectUser('{{d.id}}')"  style="font-size: 20px;" ></i>
</script>
    <script type="text/html" id="bar">
       <#-- <i class="layui-icon layui-icon-edit" lay-event="edit" style="font-size: 20px;"></i>&nbsp;&nbsp;&nbsp;-->
        <button class="layui-btn  layui-btn-normal layui-btn-xs" lay-event="edit">修改密码</button>
    </script>
<script src="${base}/js/jquery.min.js"></script>
<script src="${base}/js/layui/layui.js"></script>
<script>
layui.use(['form', 'layedit', 'laydate','table'], function(){
  var form = layui.form
  ,$ = layui.jquery
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate
  ,table = layui.table;
  table.render({
    elem: '#test'
    ,url:'${base}/user/userAdminList'//数据接口
    ,height:500
    ,cols: [[
      {field:'username',templet:function(val){
          return val.LAY_INDEX
        },align: 'center',width:60, title: '序号'}
      ,{field:'username',align: 'center', title: '账户',width:200}
      ,{field:'roleName', align: 'center',width:200,templet:function(val){
			  if(val.roleName==""||val.roleName==null){
                  return "无";
			  }else{
                  return val.roleName;
			  }
          }, title: '角色'}
      ,{field:'createTime',align: 'center',templet:function(val){
              return changeDateFormat(val.createTime);
          }, title: '创建时间',width:200}

      ,{fixed: 'right',align: 'center', title:'操作', toolbar: '#barDemo', width: '150'}
      ,{fixed: 'right',align: 'center', title:'修改密码', toolbar: '#bar', width: '150'}
    ]]
    ,id:'testReload'
   ,page: {
          layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
          ,theme: '#0092EF'
            ,limit:20
        },done: function(res, curr, count){
          this.where={};
      }
 });
   var active = {
     	offset: function(othis){
     	  var type = othis.data('type')
     	  ,text = othis.text();
 		  layer.open({
 		  type: 2,
 		  title: '添加人员',

 		  shadeClose:false ,
 		  area:['500px','380px'],
 		  content: '${base}/user/user_add',
 		    success: function (layero, index) {
                 var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
            }
 		});
 	}
   };
    $('#btn2').on('click', function(){
     var othis = $(this), method = othis.data('method');
     active[method] ? active[method].call(this, othis) : '';
   });
    //编辑弹出层
    table.on('tool(user)', function(obj){
        var layEvent = obj.event;
        if(layEvent=="edit"){
            var data = obj.data;
            //示范一个公告层
            layer.open({
                type: 2,
                title: '修改密码',

                shadeClose:false ,
                area:['500px','380px'],
                content: '${base}/user/updateUser.html',
                success: function (layero, index) {
                    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            iframeWin.$("#userId").val(data.id)
                            iframeWin.$("#username").val(data.username)

                }
            });
        }
    });

});

function delectUser(id){
layer.confirm('真的要删除吗?', function(index){

 $.ajax({
    type:"POST",
       url:"${base}/user/deleteUser",
       data:{"id":id},
           success : function(data){

           var table = layui.table;
            //表刷新方法
              table.reload('testReload', {
                   url: '${base}/user/userAdminList'
                      ,where: {} //设定异步数据接口的额外参数
                                  });
                                    layer.close(index);
                       }
                 });

} );
            }
    function selectUser(){
        var whereData={};
        whereData.username=Trim($("#demoReload").val())
        var table = layui.table;
        //表刷新方法
        table.reload('testReload', {
            url: '${base}/user/userAdminList'
            ,where: whereData
        });
    }
</script>
</body>
</html>